<?
include('db.php');
if (!isset($_GET['ask'])){die('fatal error');}else{$ask = $_GET['ask'];}
$return = '';
switch ($ask) {
case 'add':
    $query = 'SELECT songid,title,genre FROM songlist WHERE submitted = 0';
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $t = $row['songid'] . ' ' . $row['title'];
        $g = $row['genre'];
        $return = $return . $t . "\n" . $g . "\n";
    }
    break;
case 'delete':
    $query = 'SELECT songid,genre FROM deleted WHERE submitted = 0';
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $t = $row['songid'];
        $return = $return . $t . "\n";
    }
    break;
case 'users':
    break;
case 'playlists':
    $query = 'SELECT userid, playlistid, playlistname FROM playlists WHERE submitted = 0';
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $return = $return . $row['userid'] . ' ' . $row['playlistid'] . ' ' . $row['playlistname'] . "\n";
    }
    break;
case 'submitgpl':
    $name = mysql_real_escape_string($_POST['name']);
    $songs = mysql_real_escape_string($_POST['list']);
    $query = 'INSERT INTO playlists (playlistname,songidlist,submitted) VALUES ("' . $name . '","' . $songs . '", 0)';
    mysql_query($query) or die(mysql_error());
    $query = 'SELECT playlistid FROM playlists WHERE playlistname = "' . $name . '"';
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_row($result);
    $return = $row[0];
    break;
case 'updates':
	$query = 'SELECT * FROM playlists WHERE submitted = 0';
	$result = mysql_query($query) or die(mysql_error());
	if (mysql_affected_rows())
	{
		$return = '1';
	}
	else
	{
		$return = '0';
	}
	break;
}
echo $return;
?>